package com.shardingSphere.test.Controller;

import com.shardingSphere.test.Entity.Order;
import com.shardingSphere.test.Mapper.OrderDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@RestController
public class testController {
    @Autowired
    private OrderDao orderDao;

    /**
     * 自定义id
     */
    @RequestMapping("/get")
    public String get()  {

        for (long i = 0L; i < 1000; i++) {
            orderDao.insert(Order.builder()
                            .id(i)
                            .price(BigDecimal.valueOf(2.22))
                            .userId(new Random().nextInt(4))
                    .build());
        }
        return "ok";
    }

    /**
     * 通过雪花算法生成id
     */
    @RequestMapping("/get2")
    public String get2()  {

        for (long i = 0L; i < 1000; i++) {
            orderDao.insert2(Order.builder()
                    .price(BigDecimal.valueOf(2.22))
                    .userId(new Random().nextInt(4))
                    .build());
        }
        return "ok";
    }

}
